FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

# 替换aliyun的源
RUN sed -i 's/archive\.ubuntu\.com/mirrors\.aliyun\.com/g' /etc/apt/sources.list \
    && sed -i 's/security\.ubuntu\.com/mirrors\.aliyun\.com/g' /etc/apt/sources.list

# 安装基本工具和依赖
RUN apt-get update && \
    apt-get install -y wget bzip2 curl vim build-essential libmysqlclient-dev && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 解决libmysqlclient-dev安装失败的问题
ENV MYSQLCLIENT_CFLAGS="-I/usr/include/mysql"
ENV MYSQLCLIENT_LDFLAGS="-L/usr/lib/x86_64-linux-gnu -lmysqlclient"

# 下载并安装Miniconda
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /miniconda.sh && \
    /bin/bash /miniconda.sh -b -p /miniconda && \
    rm /miniconda.sh

# 配置Conda
ENV PATH=/miniconda/bin:$PATH
RUN conda update -n base -c defaults conda && \
    conda create -n book python=3.10 -y && \
    /bin/bash -c "source activate book"

# COPY工程
COPY application /app
COPY requirements.txt /app
WORKDIR /app

# 安装工程依赖
RUN /bin/bash -c "source activate book && pip install -r /app/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/"

EXPOSE 5000

CMD ["/bin/bash", "-c", "source activate book && TZ='Asia/Shanghai' gunicorn --workers 3 -b 0.0.0.0:5000 run_server:app"]
#CMD ["/bin/bash", "-c", "source activate book && flask --app run_server.py run --host=0.0.0.0"]
#CMD ["tail", "-f", "/dev/null"]
